// run: $exec < input > output
#include <iostream>
#include <algorithm>

template <class T>
T abs(T x) { return x < 0 ? -x : x; }

long long sum(long long x)
{
	long long ret = 0;
	for (; x; x /= 10)
		ret += x % 10;
	return ret;
}

int main()
{
	std::ios::sync_with_stdio(false);
	long long a, b;
	int T; std::cin >> T;
	long long max = 0;
	for (int i = 10000000; i <= 200000000; i++) {
		max = std::max(max, abs(sum(2 * i) - sum(i)));
		std::cout << "i = " << i << "    " << sum(i) << "  " << sum(2 * i) << "\n";
	}
	std::cout << max << "\n";
	return 0;
	while (T--) {
		std::cin >> a >> b;
//		std::cout << "(" << a << ", " << b << ") = ";
		bool ok = true;
		for (long long i = 1; i < 10000000; i++)
			if (a * sum(i) == b * sum(2 * i)) {
				std::cout << i << "\n";
				ok = false;
				break;
			}
		if (ok) std::cout << "0\n";
	}
}

